<template>
    <div class="integral_set">
        <header>积分设置</header>
        <div class="contents">
            <div class="ad_list">
                <div class="ad_list_title">
                    <el-button type="danger" style="background:#e7251a;" @click="levelAdd">新增等级</el-button>
                </div>
            </div>
            <div class="tables">
                <el-table v-loading="loading" :data="tableDatas" style="width: 100%">
                    <el-table-column type="index" label="排序" width="50"> </el-table-column>
                    <el-table-column prop="GRADENAME" label="会员等级" width="200"> </el-table-column>
                    <el-table-column prop="range" label="积分限制" width="200">
                        <template slot-scope="scope"> {{scope.row.STARTPOINTS}}~{{scope.row.ENDPOINTS}} </template>
                    </el-table-column>
                    <el-table-column prop="REMARK" label="升级福利" width="400"> </el-table-column>
                    <el-table-column prop="STATUS" label="状态" width="200">
                        <template slot-scope="scope">
                            <span v-if="scope.row.STATUS==1" style="display:flex;align-items:center;justify-content:center;">
                                <img src="../../assets/images/market/dot_green.png" width="16" heigth="16" alt="" />启用 </span>
                            <span v-if="scope.row.STATUS==0" style="display:flex;align-items:center;justify-content:center;">
                                <img src="../../assets/images/market/dot_red.png" width="16" heigth="16" alt="" />停用 </span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="options" label="操作" width="250">
                        <template slot-scope="scope">
                            <span class="opretions" @click="changes(scope.row.GRADEID,scope.row.STATUS)" v-if="scope.row.STATUS==1">停用</span>
                            <span class="opretions" v-else @click="changes(scope.row.GRADEID,scope.row.STATUS)">启用</span>
                            <span class="opretions" @click="goEdit(scope.row.GRADEID)"> 编辑 </span>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        name: "integral_set",
        data() {
            return {
            	loading:true,
                tableDatas: [],
                page: 1,
            };
        },
        created() {
            this.getList();
        },
        methods: {
            //积分等级列表
            getList() {
            	this.loading = true;
                this.$axiosPost('/4SCAFE/Grade/getGradeList.action').then(res => {
                    //console.log(res)
                    this.loading = false;
                    if(res.STATUS_CODE === 1) {
                        this.tableDatas = res.GRADEARR;
                    }
                })
            },
            //启用、停用
            changes(id, status) {
                this.$axiosPost('/4SCAFE/Grade/gradeUptoDown.action', {
                    GRADEID: id,
                    STATUS: status === 0 ? 1 : 0
                }).then(res => {
                    //console.log(res);
                    if(res.STATUS_CODE === 1) {
                        this.$message.success('状态已改变');
                        this.getList();
                    }
                })
            },
            // 新增等级
            levelAdd() {
                this.$router.push({
                    path: "/setting/levelAdd"
                });
            },
            //编辑等级
            goEdit(id){
            	this.$router.push({
                    path: "/setting/levelEdit/"+id
                });
            }
        }
    };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .integral_set {
        header {
            background: #fff;
            font-size: 22px;
            font-weight: 700;
            padding: 20px;
        }
        .contents {
            width: 97%;
            margin: 25px auto;
            padding: 15px 25px;
            background: #fff;
            .ad_list {
                display: flex;
                align-items: center;
                justify-content: space-between;
                .ad_list_title {
                    height: 68px;
                    padding-top: 10px;
                    font-size: 20px;
                }
                .ad_list_tab {
                    display: flex;
                    padding-top: 10px;
                }
            }
            .selected {
                margin-top: 15px;
                border: 1px solid #f0f0f0;
                border-radius: 5px;
                background: #fafafa;
                p {
                    display: flex;
                    align-items: center;
                    img {
                        width: 20px;
                        height: 20px;
                        margin: 0 10px;
                    }
                    span {
                        font-size: 16px;
                        color: #717a7d;
                        label {
                            color: #e7251a;
                        }
                    }
                }
            }
            .tables {
                margin-top: 30px;
                .el-pagination {
                    text-align: center;
                    margin-top: 30px;
                }
                .opretions {
                    color: #1d93ff;
                    cursor: pointer;
                    margin: 0 2px;
                    &:hover {
                        text-decoration: underline;
                    }
                }
            }
        }
    }
</style>